package LiKouBrushQuestions;

/**
 * @author  23737
 * @time 6.30
 */

public class June_30 {
    public static void main(String[] args) {
        System.out.println("坚持！！！进大厂");
    }
}


/**
 * @time 6.30
 * 剑指 offer 25
 * 合并两个排序的链表
 */
class ListNode{
    int val;
    ListNode next;
    ListNode(int x) {
        val = x;
    }
}

class SolutionHeBingLianBiao {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        //初始化：伪头结点dum，结点cur指向dum
        ListNode dum = new ListNode(0);
        ListNode cur = dum;
        //循环合并：当l1或者l2为空时跳出
        /**
         * 1.当l1.val<l2.val时：cur的后结点指定为l1，并l1向前走一步；
         * 2.当l1.val>l2.val时：cur的后结点指定为l2，并l2向前走一步；
         * 3.结点cur向前走一步，即cur=cur.next
         */
        while (l1 != null && l2 != null) {
            if (l1.val >= l2.val) {
                cur.next = l2;
                l2 = l2.next;
            } else {
                cur.next = l1;
                l1 = l1.next;
            }
            cur = cur.next;
        }
        //合并剩余尾部：跳出时有两种情况，即 l1为空 或 l2为空。
        /**
         * 1.l1!=null：将l1添加至结点cur之后；
         * 2.否则：将l2添加至结点cur之后
         */
        cur.next = l1 != null ? l1 : l2;
        return dum.next;
    }
}

class Test {
    public static void main(String[] args) {
        ListNode l1 = new ListNode(1);
        ListNode l2 = new ListNode(2);
        ListNode l3 = new ListNode(4);
        l1.next = l2;
        l2.next = l3;

        ListNode l4 = new ListNode(1);
        ListNode l5 = new ListNode(3);
        ListNode l6 = new ListNode(4);
        l4.next = l5;
        l5.next = l6;

        new SolutionHeBingLianBiao().mergeTwoLists(l1, l4);
    }
}

/**
 * @time 6.30  13.15
 * 搜索插入位置
 */
class SolutionsearchInsert {
    public int searchInsert(int[] nums, int target) {
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] >= target) {
                return i;
            }
            count++;
        }
        if (count>=nums.length) {
            return nums.length;
        }
        return -1;
    }
}
